using Bardent.Weapons.Components.ComponentData;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Bardent.Weapons.Components
{
    public abstract class WeaponComponent : MonoBehaviour
    {
        protected Weapon weapon;

        //protected AnimationEventHandler EventHandler => weapon.EventHandler;

        protected AnimationEventHandler eventHandler;

        protected Core Core => weapon.Core;

        protected bool isAttackActive;

        protected virtual void Start()
        {
            weapon = GetComponent<Weapon>();
            eventHandler = GetComponentInChildren<AnimationEventHandler>();
            weapon.OnEnter += HandleEnter;
            weapon.OnExit += HandleExit;
        }



        protected virtual void HandleEnter()
        {
            isAttackActive = true;
        }

        protected virtual void HandleExit()
        {
            isAttackActive = false;
        }




        protected virtual void OnDestroy()
        {
            weapon.OnEnter -= HandleEnter;
            weapon.OnExit -= HandleExit;
        }

    }

    public abstract class WeaponComponent<T1,T2> : WeaponComponent where T1:ComponentData.ComponentData<T2> where T2:AttackDatas
    {
        protected T1 data;

        protected T2 currentAttackData;

        protected override void Start()
        {
            base.Start();

            data = weapon.Data.GetData<T1>();
        }

        protected override void HandleEnter()
        {
            base.HandleEnter();

            currentAttackData = data.AttackData[weapon.CurrentAttackCounter];
        }
    }

}
